package com.lx.javasunmmrize.thread;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Description 测试juc ,一个线程安全的list??没有延时依然会出现线程不安全的问题！！！！！
 * @Author lx
 * @Date 2021/3/1 22:31
 **/
public class TestJUC {

    public static void main(String[] args) {
        CopyOnWriteArrayList list = new CopyOnWriteArrayList();
        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                list.add(Thread.currentThread().getName());
            }).start();
        }

//        try {
//            Thread.sleep(1000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println(list.size());
    }
}
